home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / DisassemblyWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  9.7 KB  |  298 lines  |  [TEXT/KAHL]

  1. /* DisassemblyWindow.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "DisassemblyWindow.h"
  31. #include "Screen.h"
  32. #include "TextEdit.h"
  33. #include "Memory.h"
  34. #include "MainWindowStuff.h"
  35. #include "GrowIcon.h"
  36. #include "Main.h"
  37. #include "WindowDispatcher.h"
  38. #include "GlobalWindowMenuList.h"
  39.  
  40.  
  41. struct DisaWindowRec
  42.     {
  43.         MainWindowRec*            Owner;
  44.         WinType*                        ScreenID;
  45.         TextEditRec*                Editor;
  46.         GenericWindowRec*        MyGenericWindow; /* how the window event dispatcher knows us */
  47.         MenuItemType*                MyMenuItem;
  48.     };
  49.  
  50.  
  51. /* create a new disassembly window.  the window is basically a non-editable text */
  52. /* field containing the Data passed in (linefeed = 0x0a).  the caller is responsible */
  53. /* for disposing of Data.  the function automatically notifies the main window */
  54. /* that it has been created. */
  55. DisaWindowRec*            NewDisassemblyWindow(char* Data, MainWindowRec* Owner)
  56.     {
  57.         DisaWindowRec*        Window;
  58.  
  59.         Window = (DisaWindowRec*)AllocPtrCanFail(sizeof(DisaWindowRec),"DisaWindowRec");
  60.         if (Window == NIL)
  61.             {
  62.              FailurePoint1:
  63.                 return NIL;
  64.             }
  65.         Window->Owner = Owner;
  66.         Window->ScreenID = MakeNewWindow(eDocumentWindow,eWindowClosable,
  67.             eWindowZoomable,eWindowResizable,GetScreenWidth()
  68.             - (2 + WindowOtherEdgeWidths(eDocumentWindow)) - 400,
  69.             2 + WindowTitleBarHeight(eDocumentWindow),400,GetScreenHeight()
  70.             - WindowTitleBarHeight(eDocumentWindow)
  71.             - WindowOtherEdgeWidths(eDocumentWindow) - 4,
  72.             (void (*)(void*))&DisassemblyWindowUpdator,Window);
  73.         if (Window->ScreenID == 0)
  74.             {
  75.              FailurePoint2:
  76.                 ReleasePtr((char*)Window);
  77.                 goto FailurePoint1;
  78.             }
  79.         SetWindowName(Window->ScreenID,"Disassembly");
  80.         Window->Editor = NewTextEdit(Window->ScreenID,
  81.             (TEScrollType)(eTEVScrollBar | eTEHScrollBar),GetMonospacedFont(),9,-1,-1,
  82.             GetWindowWidth(Window->ScreenID) + 2,GetWindowHeight(Window->ScreenID) + 2);
  83.         if (Window->Editor == NIL)
  84.             {
  85.              FailurePoint3:
  86.                 KillWindow(Window->ScreenID);
  87.                 goto FailurePoint2;
  88.             }
  89.         if (!MainWindowNewDisassemblyNotify(Owner,Window))
  90.             {
  91.              FailurePoint4:
  92.                 DisposeTextEdit(Window->Editor);
  93.                 goto FailurePoint3;
  94.             }
  95.         Window->MyGenericWindow = CheckInNewWindow(Window->ScreenID,Window,
  96.             (void (*)(void*,MyBoolean,OrdType,OrdType,ModifierFlags))&DisassemblyWindowDoIdle,
  97.             (void (*)(void*))&DisassemblyWindowBecomeActive,
  98.             (void (*)(void*))&DisassemblyWindowBecomeInactive,
  99.             (void (*)(void*))&DisassemblyWindowJustResized,
  100.             (void (*)(OrdType,OrdType,ModifierFlags,void*))&DisassemblyWindowDoMouseDown,
  101.             (void (*)(unsigned char,ModifierFlags,void*))&DisassemblyWindowDoKeyDown,
  102.             (void (*)(void*))&DisassemblyWindowClose,
  103.             (void (*)(void*))&DisassemblyWindowMenuSetup,
  104.             (void (*)(void*,MenuItemType*))&DisassemblyWindowDoMenuCommand);
  105.         if (Window->MyGenericWindow == NIL)
  106.             {
  107.              FailurePoint5:
  108.                 MainWindowDisassemblyClosingNotify(Owner,Window);
  109.                 goto FailurePoint4;
  110.             }
  111.         Window->MyMenuItem = MakeNewMenuItem(mmWindowMenu,"Disassembly",0);
  112.         if (Window->MyMenuItem == NIL)
  113.             {
  114.              FailurePoint6:
  115.                 CheckOutDyingWindow(Window->MyGenericWindow);
  116.                 goto FailurePoint5;
  117.             }
  118.         if (!RegisterWindowMenuItem(Window->MyMenuItem,(void (*)(void*))&ActivateThisWindow,
  119.             Window->ScreenID))
  120.             {
  121.              FailurePoint7:
  122.                 KillMenuItem(Window->MyMenuItem);
  123.                 goto FailurePoint6;
  124.             }
  125.         TextEditNewRawData(Window->Editor,Data,"\x0a");
  126.         return Window;
  127.     }
  128.  
  129.  
  130. /* dispose of the disassembly window.  this automatically notifies the main window */
  131. /* that it has been destroyed. */
  132. void                                DisposeDisassemblyWindow(DisaWindowRec* Window)
  133.     {
  134.         CheckPtrExistence(Window);
  135.         DeregisterWindowMenuItem(Window->MyMenuItem);
  136.         KillMenuItem(Window->MyMenuItem);
  137.         CheckOutDyingWindow(Window->MyGenericWindow);
  138.         DisposeTextEdit(Window->Editor);
  139.         KillWindow(Window->ScreenID);
  140.         ReleasePtr((char*)Window);
  141.     }
  142.  
  143.  
  144. void                                DisassemblyWindowDoIdle(DisaWindowRec* Window,
  145.                                             MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
  146.                                             ModifierFlags Modifiers)
  147.     {
  148.         CheckPtrExistence(Window);
  149.         TextEditUpdateCursor(Window->Editor);
  150.         if (CheckCursorFlag)
  151.             {
  152.                 if (TextEditIBeamTest(Window->Editor,XLoc,YLoc))
  153.                     {
  154.                         SetIBeamCursor();
  155.                     }
  156.                  else
  157.                     {
  158.                         SetArrowCursor();
  159.                     }
  160.             }
  161.     }
  162.  
  163.  
  164. void                                DisassemblyWindowBecomeActive(DisaWindowRec* Window)
  165.     {
  166.         OrdType                        XSize;
  167.         OrdType                        YSize;
  168.  
  169.         CheckPtrExistence(Window);
  170.         EnableTextEditSelection(Window->Editor);
  171.         XSize = GetWindowWidth(Window->ScreenID);
  172.         YSize = GetWindowHeight(Window->ScreenID);
  173.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  174.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(True/*enablegrowicon*/));
  175.     }
  176.  
  177.  
  178. void                                DisassemblyWindowBecomeInactive(DisaWindowRec* Window)
  179.     {
  180.         OrdType                        XSize;
  181.         OrdType                        YSize;
  182.  
  183.         CheckPtrExistence(Window);
  184.         DisableTextEditSelection(Window->Editor);
  185.         XSize = GetWindowWidth(Window->ScreenID);
  186.         YSize = GetWindowHeight(Window->ScreenID);
  187.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  188.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(False/*disablegrowicon*/));
  189.     }
  190.  
  191.  
  192. void                                DisassemblyWindowJustResized(DisaWindowRec* Window)
  193.     {
  194.         CheckPtrExistence(Window);
  195.         SetTextEditPosition(Window->Editor,-1,-1,GetWindowWidth(Window->ScreenID) + 2,
  196.             GetWindowHeight(Window->ScreenID) + 2);
  197.     }
  198.  
  199.  
  200. void                                DisassemblyWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
  201.                                             ModifierFlags Modifiers, DisaWindowRec* Window)
  202.     {
  203.         CheckPtrExistence(Window);
  204.         if ((XLoc >= GetWindowWidth(Window->ScreenID) - 15)
  205.             && (XLoc < GetWindowWidth(Window->ScreenID))
  206.             && (YLoc >= GetWindowHeight(Window->ScreenID) - 15)
  207.             && (YLoc < GetWindowHeight(Window->ScreenID)))
  208.             {
  209.                 UserGrowWindow(Window->ScreenID,XLoc,YLoc);
  210.                 DisassemblyWindowJustResized(Window);
  211.             }
  212.         else if (TextEditHitTest(Window->Editor,XLoc,YLoc))
  213.             {
  214.                 TextEditDoMouseDown(Window->Editor,XLoc,YLoc,Modifiers);
  215.             }
  216.     }
  217.  
  218.  
  219. void                                DisassemblyWindowDoKeyDown(unsigned char KeyCode,
  220.                                             ModifierFlags Modifiers, DisaWindowRec* Window)
  221.     {
  222.         CheckPtrExistence(Window);
  223.         if ((KeyCode == eLeftArrow) || (KeyCode == eRightArrow)
  224.             || (KeyCode == eUpArrow) || (KeyCode == eDownArrow))
  225.             {
  226.                 TextEditDoKeyPressed(Window->Editor,KeyCode,Modifiers);
  227.             }
  228.     }
  229.  
  230.  
  231. void                                DisassemblyWindowClose(DisaWindowRec* Window)
  232.     {
  233.         CheckPtrExistence(Window);
  234.         /* notification of closing is here and not in dispose because FunctionWindow */
  235.         /* calls dispose, so it knows that we are dying, but this routine handles */
  236.         /* a user close, which FunctionWindow doesn't know about */
  237.         MainWindowDisassemblyClosingNotify(Window->Owner,Window);
  238.         DisposeDisassemblyWindow(Window);
  239.     }
  240.  
  241.  
  242. void                                DisassemblyWindowUpdator(DisaWindowRec* Window)
  243.     {
  244.         OrdType                        XSize;
  245.         OrdType                        YSize;
  246.  
  247.         CheckPtrExistence((char*)Window);
  248.         TextEditFullRedraw(Window->Editor);
  249.         XSize = GetWindowWidth(Window->ScreenID);
  250.         YSize = GetWindowHeight(Window->ScreenID);
  251.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  252.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,
  253.             GetGrowIcon(Window->MyGenericWindow == GetCurrentWindowID()));
  254.     }
  255.  
  256.  
  257. void                                DisassemblyWindowMenuSetup(DisaWindowRec* Window)
  258.     {
  259.         CheckPtrExistence(Window);
  260.         MainWindowEnableGlobalMenus(Window->Owner);
  261.         ChangeItemName(mCloseFile,"Close Disassembly Viewer");
  262.         EnableMenuItem(mCloseFile);
  263.         if (TextEditIsThereValidSelection(Window->Editor))
  264.             {
  265.                 EnableMenuItem(mCopy);
  266.                 ChangeItemName(mCopy,"Copy Text");
  267.             }
  268.         EnableMenuItem(mSelectAll);
  269.         ChangeItemName(mSelectAll,"Select All Text");
  270.         SetItemCheckmark(Window->MyMenuItem);
  271.     }
  272.  
  273.  
  274. void                                DisassemblyWindowDoMenuCommand(DisaWindowRec* Window,
  275.                                             MenuItemType* MenuItem)
  276.     {
  277.         if (MainWindowDoGlobalMenuItem(Window->Owner,MenuItem))
  278.             {
  279.             }
  280.         else if (MenuItem == mCloseFile)
  281.             {
  282.                 DisassemblyWindowClose(Window);
  283.             }
  284.         else if (MenuItem == mCopy)
  285.             {
  286.                 TextEditDoMenuCopy(Window->Editor);
  287.             }
  288.         else if (MenuItem == mSelectAll)
  289.             {
  290.                 TextEditDoMenuSelectAll(Window->Editor);
  291.             }
  292.         else
  293.             {
  294.                 EXECUTE(PRERR(AllowResume,
  295.                     "DisassemblyWindowDoMenuCommand:  unknown menu command"));
  296.             }
  297.     }
  298.